package com.zl.zlproject.base.activity;

import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zl.zlproject.R;
import com.zl.zlproject.widget.ZlLayoutManager;


/**
 * Created by 郑磊 on 2018/6/17.
 */

public abstract class DefaultMvpActivity extends BaseMvpActivity implements OnRefreshListener {


    ViewStub mViewstubContainer;
    protected ZlLayoutManager mLayoutManager;
    protected SmartRefreshLayout mRefreshLayout;

    protected ImageView mIvBack;
    protected TextView mTvTitle;
    protected Toolbar mToolbar;
    protected LinearLayout mLlError;

    @Override
    protected int getContentViewRes() {
        return R.layout.default_mvp;
    }


    @Override
    protected void  initBefore() {
        mViewstubContainer = findViewById(R.id.viewstub_container);
        mLayoutManager =findViewById(R.id.layout_manager);
        mRefreshLayout =findViewById(R.id.refresh_layout);
        mIvBack =findViewById(R.id.iv_back);
        mTvTitle =findViewById(R.id.tv_title);
        mToolbar =findViewById(R.id.toolbar);
        mLlError =findViewById(R.id.ll_error);

        mViewstubContainer.setLayoutResource(getContentRes());
        mRefreshLayout.setOnRefreshListener(this);

//        mRefreshLayout.setRefreshHeader(new ClassicsHeader(this).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.colorPrimary).setAccentColorId(android.R.color.white));
        mLayoutManager.showContent();
        mRefreshLayout.autoRefresh();
    }

    @Override
    protected void initView() {
        super.initView();
        mViewstubContainer = findViewById(R.id.viewstub_container);
        mViewstubContainer.setInflatedId(getContentRes());
        mRefreshLayout.setOnRefreshListener(this);

//        mLayoutManager.showLoading();

        mRefreshLayout.getLayout().postDelayed(new Runnable() {
            @Override
            public void run() {
                mRefreshLayout.autoRefresh();

            }
        }, 3000);
    }

    protected abstract int getContentRes();



    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

    }
}
